import { createStore } from 'vuex'
import getters from './getters'

// you don't need 'import app from './modules/app.js''
// it will auto import all vuex module from moludes file
const modulesFiles = import.meta.globEager('./modules/**.js')
const modules = Object.keys(modulesFiles).reduce((modules, modulePath) => {
    const moduleName = modulePath.replace(/^\.\/modules\/(.*)\.\w+$/, '$1')
    const value = modulesFiles[modulePath]
    modules[moduleName] = value.default
    return modules
}, {})

// create a new store
const store = createStore({
    modules,
    getters
})

export default store